package lng.site.tatoo.jobEmail;


import java.io.InputStream;
import java.net.URL;

import java.net.URLConnection;

import javax.net.ssl.HttpsURLConnection;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.xml.sax.helpers.DefaultHandler;

public class Jobs2 extends DefaultHandler{
	@Autowired
	private DefaultHandler gestionnaire;
	public void runAction() {

		String loginPassword ="tmavdm:rootvdm2012";
		String encoded = new sun.misc.BASE64Encoder().encode(loginPassword.getBytes());
		try {
			// Create a URLConnection object for a URL
			URL url = new URL("https://mail.google.com/mail/feed/atom/");
			URLConnection conn = url.openConnection();
			conn.setRequestProperty ("Authorization", "Basic " + encoded);
			
			HttpsURLConnection httpsConn;

			httpsConn = (HttpsURLConnection) conn;
			
			SAXParserFactory fabrique = SAXParserFactory.newInstance();
			SAXParser parseur = fabrique.newSAXParser();
			parseur.parse(httpsConn.getInputStream(), getGestionnaire());
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
	public DefaultHandler getGestionnaire() {
		return gestionnaire;
	}
	public void setGestionnaire(DefaultHandler gestionnaire) {
		this.gestionnaire = gestionnaire;
	}
}
